
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>第 6 章 Key-Value 类型 RDD 的数据分区器 · 大数据 bigdata_spark_atguigu 课堂笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content=" 李振超">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-solarizedlight.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-change_girls/girls.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../styles/website.css">
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="di-7-zhang.html" />
    
    
    <link rel="prev" href="di-5-zhang-rdd-bian-cheng/510-she-zhi-jian-cha-dian.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://www.atguigu.com/" target="_blank" class="custom-link">联系我们</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">第 1 部分 Spark 基础</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    第 1 章 Spark 概述
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" data-path="../11-shi-yao-shi-spark.html">
            
                <a href="../11-shi-yao-shi-spark.html">
            
                    
                    1.1 什么是 Spark
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2" data-path="../13-spark-te-dian.html">
            
                <a href="../13-spark-te-dian.html">
            
                    
                    1.2 Spark 特点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3" data-path="../13-spark-nei-zhi-mo-kuai-jie-shao.html">
            
                <a href="../13-spark-nei-zhi-mo-kuai-jie-shao.html">
            
                    
                    1.3 Spark 内置模块介绍
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter1.html">
            
                <a href="../chapter1.html">
            
                    
                    第 2 章 Spark 运行模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../chapter1/21-local-mo-shi.html">
            
                <a href="../chapter1/21-local-mo-shi.html">
            
                    
                    2.1 Local 模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../chapter1/22-spark-he-xin-gai-nian-jie-shao.html">
            
                <a href="../chapter1/22-spark-he-xin-gai-nian-jie-shao.html">
            
                    
                    2.2 Spark 核心概念介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../chapter1/22-standalone-mo-shi.html">
            
                <a href="../chapter1/22-standalone-mo-shi.html">
            
                    
                    2.3 Standalone 模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.3.1" data-path="../chapter1/231-pei-zhi-standalone-mo-shi.html">
            
                <a href="../chapter1/231-pei-zhi-standalone-mo-shi.html">
            
                    
                    2.3.1 配置 Standalone 模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.2" data-path="../chapter1/232-shi-yong-standalone-mo-shi-yun-xing-ji-suan-pi-de-cheng-xu.html">
            
                <a href="../chapter1/232-shi-yong-standalone-mo-shi-yun-xing-ji-suan-pi-de-cheng-xu.html">
            
                    
                    2.3.2 使用 Standalone 模式运行计算 PI 的程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.3" data-path="../chapter1/233-zai-standalone-mo-shi-xia-qi-dong-spark-shell.html">
            
                <a href="../chapter1/233-zai-standalone-mo-shi-xia-qi-dong-spark-shell.html">
            
                    
                    2.3.3 在 Standalone 模式下启动 Spark-shell
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.4" data-path="../chapter1/24-pei-zhi-spark-ren-wu-li-shi-fu-wu-qi.html">
            
                <a href="../chapter1/24-pei-zhi-spark-ren-wu-li-shi-fu-wu-qi.html">
            
                    
                    2.3.4 配置 Spark 任务历史服务器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.5" data-path="../chapter1/25-ha-pei-7f6e28-wei-mater-pei-7f6e29.html">
            
                <a href="../chapter1/25-ha-pei-7f6e28-wei-mater-pei-7f6e29.html">
            
                    
                    2.3.5 HA 配置(为 Mater 配置)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.6" data-path="../chapter1/233-standalone-gong-zuo-mo-shi-tu-jie.html">
            
                <a href="../chapter1/233-standalone-gong-zuo-mo-shi-tu-jie.html">
            
                    
                    2.3.6 Standalone 工作模式图解
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../chapter1/24-yarn-mo-shi.html">
            
                <a href="../chapter1/24-yarn-mo-shi.html">
            
                    
                    2.4 Yarn 模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../chapter1/25-mesos-mo-shi.html">
            
                <a href="../chapter1/25-mesos-mo-shi.html">
            
                    
                    2.5 Mesos 模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../chapter1/26-ji-zhong-yun-xing-mo-shi-de-dui-bi.html">
            
                <a href="../chapter1/26-ji-zhong-yun-xing-mo-shi-de-dui-bi.html">
            
                    
                    2.6 几种运行模式的对比
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../di-3-zhang-an-li-shi-cao.html">
            
                <a href="../di-3-zhang-an-li-shi-cao.html">
            
                    
                    第 3 章 案例实操
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../di-3-zhang-an-li-shi-cao/31-bian-xie-wordcount-cheng-xu.html">
            
                <a href="../di-3-zhang-an-li-shi-cao/31-bian-xie-wordcount-cheng-xu.html">
            
                    
                    3.1 编写 WordCount 程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../di-3-zhang-an-li-shi-cao/32-ce-shi.html">
            
                <a href="../di-3-zhang-an-li-shi-cao/32-ce-shi.html">
            
                    
                    3.2 测试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">第 2 部分 Spark Core</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="di-4-zhang-rdd-gai-shu.html">
            
                <a href="di-4-zhang-rdd-gai-shu.html">
            
                    
                    第 4 章 RDD 概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="di-5-zhang-rdd-bian-cheng.html">
            
                <a href="di-5-zhang-rdd-bian-cheng.html">
            
                    
                    第 5 章 RDD 编程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="di-5-zhang-rdd-bian-cheng/51-rdd-bian-cheng-mo-xing.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/51-rdd-bian-cheng-mo-xing.html">
            
                    
                    5.1 RDD 编程模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.2" data-path="di-5-zhang-rdd-bian-cheng/52-rdd-de-chuang-jian.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/52-rdd-de-chuang-jian.html">
            
                    
                    5.2 RDD 的创建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.3" data-path="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan.html">
            
                    
                    5.3 RDD 的转换(transformation)
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.3.1" data-path="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan/531-value-lei-xing.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan/531-value-lei-xing.html">
            
                    
                    5.3.1 Value 类型---1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.3.2" data-path="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan/531-value-lei-xing-2.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan/531-value-lei-xing-2.html">
            
                    
                    5.3.1 Value 类型---2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.3.3" data-path="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan/532-shuang-value-lei-xing.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan/532-shuang-value-lei-xing.html">
            
                    
                    5.3.2 双 Value 类型交互
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.3.4" data-path="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan/533-key-value-lei-xing.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan/533-key-value-lei-xing.html">
            
                    
                    5.3.3 Key-Value 类型--1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.3.5" data-path="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan/533-key-value-lei-578b-2.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan/533-key-value-lei-578b-2.html">
            
                    
                    5.3.3 Key-Value 类型---2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.3.6" data-path="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan/534-an-li-shi-cao.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/53-rdd-de-zhuan-huan/534-an-li-shi-cao.html">
            
                    
                    5.3.4 案例实操
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2.4" data-path="di-5-zhang-rdd-bian-cheng/54-rddde-action-cao-zuo.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/54-rddde-action-cao-zuo.html">
            
                    
                    5.4 RDD的 Action 操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.5" data-path="di-5-zhang-rdd-bian-cheng/55-rdd-zhong-han-shu-de-chuan-di.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/55-rdd-zhong-han-shu-de-chuan-di.html">
            
                    
                    5.5 RDD 中函数的传递
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.6" data-path="di-5-zhang-rdd-bian-cheng/56-rdd-de-yi-lai-guan-xi.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/56-rdd-de-yi-lai-guan-xi.html">
            
                    
                    5.6 RDD 的依赖关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.7" data-path="di-5-zhang-rdd-bian-cheng/57-spark-zhong-de-job-diao-du.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/57-spark-zhong-de-job-diao-du.html">
            
                    
                    5.7 Spark 中的 Job 调度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.8" data-path="di-5-zhang-rdd-bian-cheng/58-spark-job-de-hua-fen.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/58-spark-job-de-hua-fen.html">
            
                    
                    5.8 Spark Job 的划分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.9" data-path="di-5-zhang-rdd-bian-cheng/50-rdd-de-chi-jiu-hua.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/50-rdd-de-chi-jiu-hua.html">
            
                    
                    5.9 RDD 的持久化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.10" data-path="di-5-zhang-rdd-bian-cheng/510-she-zhi-jian-cha-dian.html">
            
                <a href="di-5-zhang-rdd-bian-cheng/510-she-zhi-jian-cha-dian.html">
            
                    
                    5.10 设置检查点
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="2.3" data-path="di-6-zhang-key-value-lei-xing-rdd-de-shu-ju-fen-qu.html">
            
                <a href="di-6-zhang-key-value-lei-xing-rdd-de-shu-ju-fen-qu.html">
            
                    
                    第 6 章 Key-Value 类型 RDD 的数据分区器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="di-7-zhang.html">
            
                <a href="di-7-zhang.html">
            
                    
                    第 7 章 文件中数据的读取和保存
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="di-7-zhang/71-du-xie-text-wen-jian.html">
            
                <a href="di-7-zhang/71-du-xie-text-wen-jian.html">
            
                    
                    7.1 读写 Text 文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="di-7-zhang/72-du-xie-json-wen-jian.html">
            
                <a href="di-7-zhang/72-du-xie-json-wen-jian.html">
            
                    
                    7.2 读写 Json 文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="di-7-zhang/73-du-xie-sequence-wen-jian.html">
            
                <a href="di-7-zhang/73-du-xie-sequence-wen-jian.html">
            
                    
                    7.3 读写 Sequence 文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.4" data-path="di-7-zhang/74-du-xie-object-wen-jian.html">
            
                <a href="di-7-zhang/74-du-xie-object-wen-jian.html">
            
                    
                    7.4 读写 Object 文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.5" data-path="di-7-zhang/75-cong-hdfs-du-xie-wen-jian.html">
            
                <a href="di-7-zhang/75-cong-hdfs-du-xie-wen-jian.html">
            
                    
                    7.5 从 HDFS 读写文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.6" data-path="di-7-zhang/76-cong-mysql-shu-ju-du-xie-wen-jian.html">
            
                <a href="di-7-zhang/76-cong-mysql-shu-ju-du-xie-wen-jian.html">
            
                    
                    7.6 从 Mysql 数据读写文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.7" data-path="di-7-zhang/77-cong-hbase-du-xie-wen-jian.html">
            
                <a href="di-7-zhang/77-cong-hbase-du-xie-wen-jian.html">
            
                    
                    7.7 从 Hbase 读写文件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="di-8-zhang-rdd-bian-cheng-jin-jie.html">
            
                <a href="di-8-zhang-rdd-bian-cheng-jin-jie.html">
            
                    
                    第 8 章 RDD 编程进阶
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="di-8-zhang-rdd-bian-cheng-jin-jie/81-lei-jia-qi.html">
            
                <a href="di-8-zhang-rdd-bian-cheng-jin-jie/81-lei-jia-qi.html">
            
                    
                    8.1 累加器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.2" data-path="di-8-zhang-rdd-bian-cheng-jin-jie/82-guang-bo-bian-liang.html">
            
                <a href="di-8-zhang-rdd-bian-cheng-jin-jie/82-guang-bo-bian-liang.html">
            
                    
                    8.2 广播变量
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">第 3 部分 Spark Sql</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../di-3-bu-fen-spark-sql/di-9-zhang-spark-sql-gai-shu.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-9-zhang-spark-sql-gai-shu.html">
            
                    
                    第 9 章 Spark SQL 概述
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../di-3-bu-fen-spark-sql/di-9-zhang-spark-sql-gai-shu/91-11-shi-yao-shi-spark-sql.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-9-zhang-spark-sql-gai-shu/91-11-shi-yao-shi-spark-sql.html">
            
                    
                    9.1  什么是 Spark SQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../di-3-bu-fen-spark-sql/di-9-zhang-spark-sql-gai-shu/92-spark-sql-de-te-dian.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-9-zhang-spark-sql-gai-shu/92-spark-sql-de-te-dian.html">
            
                    
                    9.2 Spark SQL 的特点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="../di-3-bu-fen-spark-sql/di-9-zhang-spark-sql-gai-shu/93-shi-yao-shi-dataframe.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-9-zhang-spark-sql-gai-shu/93-shi-yao-shi-dataframe.html">
            
                    
                    9.3 什么是 DataFrame
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" data-path="../di-3-bu-fen-spark-sql/di-9-zhang-spark-sql-gai-shu/94-shi-yao-shi-dataset.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-9-zhang-spark-sql-gai-shu/94-shi-yao-shi-dataset.html">
            
                    
                    9.4 什么是 DataSet
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng.html">
            
                    
                    第 10 章 Spark SQL 编程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.1" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/101-sparksession.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/101-sparksession.html">
            
                    
                    10.1 SparkSession
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.2" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/102-shi-yong-dataframe-jin-xing-bian-cheng.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/102-shi-yong-dataframe-jin-xing-bian-cheng.html">
            
                    
                    10.2 使用 DataFrame 进行编程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.2.1" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/102-shi-yong-dataframe-jin-xing-bian-cheng/1021-chuang-jian-dataframe.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/102-shi-yong-dataframe-jin-xing-bian-cheng/1021-chuang-jian-dataframe.html">
            
                    
                    10.2.1 创建 DataFrame
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.2.2" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/102-shi-yong-dataframe-jin-xing-bian-cheng/1022-dataframe-yu-fa-feng-ge.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/102-shi-yong-dataframe-jin-xing-bian-cheng/1022-dataframe-yu-fa-feng-ge.html">
            
                    
                    10.2.2 DataFrame 语法风格
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.2.3" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/102-shi-yong-dataframe-jin-xing-bian-cheng/1023-rdd-zhuan-huan-wei-dataframe.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/102-shi-yong-dataframe-jin-xing-bian-cheng/1023-rdd-zhuan-huan-wei-dataframe.html">
            
                    
                    10.2.3 RDD 和 DataFrame 的交互
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.2.3" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/103-shi-yong-dataset-jin-xing-bian-cheng.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/103-shi-yong-dataset-jin-xing-bian-cheng.html">
            
                    
                    10.3 使用 DataSet 进行编程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.3.1" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/103-shi-yong-dataset-jin-xing-bian-cheng/1031-chuang-jian-dataset.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/103-shi-yong-dataset-jin-xing-bian-cheng/1031-chuang-jian-dataset.html">
            
                    
                    10.3.1 创建 DataSet
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.3.2" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/103-shi-yong-dataset-jin-xing-bian-cheng/1032-rdd-he-dataset-de-jiao-hu.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/103-shi-yong-dataset-jin-xing-bian-cheng/1032-rdd-he-dataset-de-jiao-hu.html">
            
                    
                    10.3.2 RDD 和 DataSet 的交互
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.2.4" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/104-dataframe-he-dataset-zhi-jian-de-jiao-hu.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/104-dataframe-he-dataset-zhi-jian-de-jiao-hu.html">
            
                    
                    10.4 DataFrame 和 DataSet 之间的交互
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.5" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/105-rdd-dataframehe-dataset-zhi-jian-de-guan-xi.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/105-rdd-dataframehe-dataset-zhi-jian-de-guan-xi.html">
            
                    
                    10.5 RDD, DataFrame和 DataSet 之间的关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.6" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/106-shi-yong-ideachuang-jian-sparksql-cheng-xu.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/106-shi-yong-ideachuang-jian-sparksql-cheng-xu.html">
            
                    
                    10.6 使用 IDEA 创建SparkSQL 程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.7" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/107-zi-ding-yi-sparksql-han-shu.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/107-zi-ding-yi-sparksql-han-shu.html">
            
                    
                    10.7 自定义 SparkSQL 函数
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.7.1" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/107-zi-ding-yi-sparksql-han-shu/1071-zi-ding-yi-udf-han-shu.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/107-zi-ding-yi-sparksql-han-shu/1071-zi-ding-yi-udf-han-shu.html">
            
                    
                    10.7.1 自定义 UDF 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.7.2" data-path="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/107-zi-ding-yi-sparksql-han-shu/1072-yong-hu-zi-ding-hui-ju-he-han-shu.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-10-zhang-spark-sql-bian-cheng/107-zi-ding-yi-sparksql-han-shu/1072-yong-hu-zi-ding-hui-ju-he-han-shu.html">
            
                    
                    10.7.2 用户自定会聚合函数
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../di-3-bu-fen-spark-sql/di-11-zhang-spark-sql-shu-ju-yuan.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-11-zhang-spark-sql-shu-ju-yuan.html">
            
                    
                    第 11 章 Spark SQL 数据源
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="../di-3-bu-fen-spark-sql/di-11-zhang-spark-sql-shu-ju-yuan/111-tong-yong-jia-zai-he-bao-cun-han-shu.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-11-zhang-spark-sql-shu-ju-yuan/111-tong-yong-jia-zai-he-bao-cun-han-shu.html">
            
                    
                    11.1 通用加载和保存函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="../di-3-bu-fen-spark-sql/di-11-zhang-spark-sql-shu-ju-yuan/112-jia-zai-json-wen-jian.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-11-zhang-spark-sql-shu-ju-yuan/112-jia-zai-json-wen-jian.html">
            
                    
                    11.2 加载 JSON 文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="../di-3-bu-fen-spark-sql/di-11-zhang-spark-sql-shu-ju-yuan/113-du-qu-parquet-wen-jian.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-11-zhang-spark-sql-shu-ju-yuan/113-du-qu-parquet-wen-jian.html">
            
                    
                    11.3 读取 Parquet 文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.4" data-path="../di-3-bu-fen-spark-sql/di-11-zhang-spark-sql-shu-ju-yuan/113-jdbc.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-11-zhang-spark-sql-shu-ju-yuan/113-jdbc.html">
            
                    
                    11.3 JDBC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.5" data-path="../di-3-bu-fen-spark-sql/di-11-zhang-spark-sql-shu-ju-yuan/114-hive-shu-ju-ku.html">
            
                <a href="../di-3-bu-fen-spark-sql/di-11-zhang-spark-sql-shu-ju-yuan/114-hive-shu-ju-ku.html">
            
                    
                    11.4 Hive 数据库
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">第 4 部分 Spark Streaming</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../di-4-bu-fen-spark-streaming/di-13-zhang-spark-streaming-gai-shu.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-13-zhang-spark-streaming-gai-shu.html">
            
                    
                    第 13 章 Spark Streaming 概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../di-4-bu-fen-spark-streaming/di-14-zhang-dstream-ru-men.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-14-zhang-dstream-ru-men.html">
            
                    
                    第 14 章 DStream 入门
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.2.1" data-path="../di-4-bu-fen-spark-streaming/di-14-zhang-dstream-ru-men/141-wordcount-an-li.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-14-zhang-dstream-ru-men/141-wordcount-an-li.html">
            
                    
                    14.1 wordcount 案例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2.2" data-path="../di-4-bu-fen-spark-streaming/di-14-zhang-dstream-ru-men/142-wordcount-an-li-jie-xi.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-14-zhang-dstream-ru-men/142-wordcount-an-li-jie-xi.html">
            
                    
                    14.2 wordcount 案例解析
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../di-4-bu-fen-spark-streaming/di-15-zhang-dstream-chuang-jian.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-15-zhang-dstream-chuang-jian.html">
            
                    
                    第 15 章 DStream 创建
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.3.1" data-path="../di-4-bu-fen-spark-streaming/di-15-zhang-dstream-chuang-jian/152-rdd-dui-lie.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-15-zhang-dstream-chuang-jian/152-rdd-dui-lie.html">
            
                    
                    15.1 RDD 队列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.2" data-path="../di-4-bu-fen-spark-streaming/di-15-zhang-dstream-chuang-jian/153-zi-ding-yi-shu-ju-yuan.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-15-zhang-dstream-chuang-jian/153-zi-ding-yi-shu-ju-yuan.html">
            
                    
                    15.2 自定义数据源
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.3" data-path="../di-4-bu-fen-spark-streaming/di-15-zhang-dstream-chuang-jian/154-kafkashu-ju-yuan.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-15-zhang-dstream-chuang-jian/154-kafkashu-ju-yuan.html">
            
                    
                    15.3 Kafka数据源
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.3.3.1" data-path="../di-4-bu-fen-spark-streaming/di-15-zhang-dstream-chuang-jian/154-kafkashu-ju-yuan/gao-jiapi.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-15-zhang-dstream-chuang-jian/154-kafkashu-ju-yuan/gao-jiapi.html">
            
                    
                    高级 API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.3.2" data-path="../di-4-bu-fen-spark-streaming/di-15-zhang-dstream-chuang-jian/154-kafkashu-ju-yuan/di-ji-api.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-15-zhang-dstream-chuang-jian/154-kafkashu-ju-yuan/di-ji-api.html">
            
                    
                    低级 API
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../di-4-bu-fen-spark-streaming/di-16-zhang-dstream-zhuan-huan.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-16-zhang-dstream-zhuan-huan.html">
            
                    
                    第 16 章 DStream 转换
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.4.1" data-path="../di-4-bu-fen-spark-streaming/di-16-zhang-dstream-zhuan-huan/161-wu-zhuang-tai-zhuan-huan-cao-zuo.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-16-zhang-dstream-zhuan-huan/161-wu-zhuang-tai-zhuan-huan-cao-zuo.html">
            
                    
                    16.1 无状态转换操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.4.1.1" data-path="../di-4-bu-fen-spark-streaming/di-16-zhang-dstream-zhuan-huan/161-wu-zhuang-tai-zhuan-huan-cao-zuo/1611-transform-cao-zuo.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-16-zhang-dstream-zhuan-huan/161-wu-zhuang-tai-zhuan-huan-cao-zuo/1611-transform-cao-zuo.html">
            
                    
                    16.1.1 transform 操作
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.4.2" data-path="../di-4-bu-fen-spark-streaming/di-16-zhang-dstream-zhuan-huan/162-you-zhuang-tai-zhuan-huan-cao-zuo.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-16-zhang-dstream-zhuan-huan/162-you-zhuang-tai-zhuan-huan-cao-zuo.html">
            
                    
                    16.2 有状态转换操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.4.2.1" data-path="../di-4-bu-fen-spark-streaming/di-16-zhang-dstream-zhuan-huan/162-you-zhuang-tai-zhuan-huan-cao-zuo/1621-updatestatebykey.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-16-zhang-dstream-zhuan-huan/162-you-zhuang-tai-zhuan-huan-cao-zuo/1621-updatestatebykey.html">
            
                    
                    16.2.1 updateStateByKey
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4.2.2" data-path="../di-4-bu-fen-spark-streaming/di-16-zhang-dstream-zhuan-huan/162-you-zhuang-tai-zhuan-huan-cao-zuo/1622-window-cao-zuo.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-16-zhang-dstream-zhuan-huan/162-you-zhuang-tai-zhuan-huan-cao-zuo/1622-window-cao-zuo.html">
            
                    
                    16.2.2 window 操作
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../di-4-bu-fen-spark-streaming/di-17-zhang-dstream-shu-chu.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-17-zhang-dstream-shu-chu.html">
            
                    
                    第 17 章 DStream 输出
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="../di-4-bu-fen-spark-streaming/di-18-zhang-dstream-bian-cheng-jin-jie.html">
            
                <a href="../di-4-bu-fen-spark-streaming/di-18-zhang-dstream-bian-cheng-jin-jie.html">
            
                    
                    第 18 章 DStream 编程进阶
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >第 6 章 Key-Value 类型 RDD 的数据分区器</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x7B2C;-6-&#x7AE0;-key-value-&#x7C7B;&#x578B;-rdd-&#x7684;&#x6570;&#x636E;&#x5206;&#x533A;&#x5668;">&#x7B2C; 6 &#x7AE0; Key-Value &#x7C7B;&#x578B; RDD &#x7684;&#x6570;&#x636E;&#x5206;&#x533A;&#x5668;</h1>
<p>&#x5BF9;&#x4E8E;&#x53EA;&#x5B58;&#x50A8; <code>value</code>&#x7684; RDD, &#x4E0D;&#x9700;&#x8981;&#x5206;&#x533A;&#x5668;.</p>
<p>&#x53EA;&#x6709;&#x5B58;&#x50A8;<code>Key-Value</code>&#x7C7B;&#x578B;&#x7684;&#x624D;&#x4F1A;&#x9700;&#x8981;&#x5206;&#x533A;&#x5668;.</p>
<p>Spark &#x76EE;&#x524D;&#x652F;&#x6301; Hash &#x5206;&#x533A;&#x548C; Range &#x5206;&#x533A;&#xFF0C;&#x7528;&#x6237;&#x4E5F;&#x53EF;&#x4EE5;&#x81EA;&#x5B9A;&#x4E49;&#x5206;&#x533A;.</p>
<p>Hash &#x5206;&#x533A;&#x4E3A;&#x5F53;&#x524D;&#x7684;&#x9ED8;&#x8BA4;&#x5206;&#x533A;&#xFF0C;Spark &#x4E2D;&#x5206;&#x533A;&#x5668;&#x76F4;&#x63A5;&#x51B3;&#x5B9A;&#x4E86; RDD &#x4E2D;&#x5206;&#x533A;&#x7684;&#x4E2A;&#x6570;&#x3001;RDD &#x4E2D;&#x6BCF;&#x6761;&#x6570;&#x636E;&#x7ECF;&#x8FC7; Shuffle &#x8FC7;&#x7A0B;&#x5C5E;&#x4E8E;&#x54EA;&#x4E2A;&#x5206;&#x533A;&#x548C; Reduce &#x7684;&#x4E2A;&#x6570;.</p>
<h2 id="&#x67E5;&#x770B;-rdd-&#x7684;&#x5206;&#x533A;">&#x67E5;&#x770B; RDD &#x7684;&#x5206;&#x533A;</h2>
<h3 id="value-rdd-&#x7684;&#x5206;&#x533A;&#x5668;"><code>value</code> RDD &#x7684;&#x5206;&#x533A;&#x5668;</h3>
<pre class="language-"><code class="lang-scala">scala<span class="token operator">&gt;</span> <span class="token keyword">val</span> rdd1 <span class="token operator">=</span> sc<span class="token punctuation">.</span>parallelize<span class="token punctuation">(</span>Array<span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
rdd1<span class="token operator">:</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>spark<span class="token punctuation">.</span>rdd<span class="token punctuation">.</span>RDD<span class="token punctuation">[</span><span class="token builtin">Int</span><span class="token punctuation">]</span> <span class="token operator">=</span> ParallelCollectionRDD<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span> at parallelize at <span class="token generics function"><span class="token punctuation">&lt;</span>console<span class="token punctuation">&gt;</span></span><span class="token operator">:</span><span class="token number">25</span>

scala<span class="token operator">&gt;</span> rdd1<span class="token punctuation">.</span>partitioner
res8<span class="token operator">:</span> Option<span class="token punctuation">[</span>org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>spark<span class="token punctuation">.</span>Partitioner<span class="token punctuation">]</span> <span class="token operator">=</span> None
</code></pre>
<h3 id="key-value-rdd-&#x7684;&#x5206;&#x533A;&#x5668;"><code>key-value</code> RDD &#x7684;&#x5206;&#x533A;&#x5668;</h3>
<pre class="language-"><code class="lang-scala">scala<span class="token operator">&gt;</span> <span class="token keyword">val</span> rdd1 <span class="token operator">=</span> sc<span class="token punctuation">.</span>parallelize<span class="token punctuation">(</span>Array<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">&quot;world&quot;</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
rdd1<span class="token operator">:</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>spark<span class="token punctuation">.</span>rdd<span class="token punctuation">.</span>RDD<span class="token punctuation">[</span><span class="token punctuation">(</span><span class="token builtin">String</span><span class="token punctuation">,</span> <span class="token builtin">Int</span><span class="token punctuation">)</span><span class="token punctuation">]</span> <span class="token operator">=</span> ParallelCollectionRDD<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span> at parallelize at <span class="token generics function"><span class="token punctuation">&lt;</span>console<span class="token punctuation">&gt;</span></span><span class="token operator">:</span><span class="token number">25</span>

scala<span class="token operator">&gt;</span> rdd1<span class="token punctuation">.</span>partitioner
res11<span class="token operator">:</span> Option<span class="token punctuation">[</span>org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>spark<span class="token punctuation">.</span>Partitioner<span class="token punctuation">]</span> <span class="token operator">=</span> None

<span class="token comment">// &#x5BFC;&#x5165;HashPartitioner</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>spark<span class="token punctuation">.</span>HashPartitioner
<span class="token comment">// &#x5BF9; rdd1 &#x91CD;&#x65B0;&#x5206;&#x533A;, &#x5F97;&#x5230;&#x5206;&#x533A;&#x540E;&#x7684; RDD, &#x5206;&#x533A;&#x5668;&#x4F7F;&#x7528; HashPartitioner</span>
scala<span class="token operator">&gt;</span> <span class="token keyword">val</span> rdd2 <span class="token operator">=</span> rdd1<span class="token punctuation">.</span>partitionBy<span class="token punctuation">(</span><span class="token keyword">new</span> HashPartitioner<span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
rdd2<span class="token operator">:</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>spark<span class="token punctuation">.</span>rdd<span class="token punctuation">.</span>RDD<span class="token punctuation">[</span><span class="token punctuation">(</span><span class="token builtin">String</span><span class="token punctuation">,</span> <span class="token builtin">Int</span><span class="token punctuation">)</span><span class="token punctuation">]</span> <span class="token operator">=</span> ShuffledRDD<span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span> at partitionBy at <span class="token generics function"><span class="token punctuation">&lt;</span>console<span class="token punctuation">&gt;</span></span><span class="token operator">:</span><span class="token number">27</span>

scala<span class="token operator">&gt;</span> rdd2<span class="token punctuation">.</span>partitioner
res14<span class="token operator">:</span> Option<span class="token punctuation">[</span>org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>spark<span class="token punctuation">.</span>Partitioner<span class="token punctuation">]</span> <span class="token operator">=</span> Some<span class="token punctuation">(</span>org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>spark<span class="token punctuation">.</span>HashPartitioner<span class="token annotation punctuation">@3</span><span class="token punctuation">)</span>
</code></pre>
<hr>
<h2 id="hashpartitioner"><code>HashPartitioner</code></h2>
<p><code>HashPartitioner</code>&#x5206;&#x533A;&#x7684;&#x539F;&#x7406;&#xFF1A;&#x5BF9;&#x4E8E;&#x7ED9;&#x5B9A;&#x7684;<code>key</code>&#xFF0C;&#x8BA1;&#x7B97;&#x5176;<code>hashCode</code>&#xFF0C;&#x5E76;&#x9664;&#x4EE5;&#x5206;&#x533A;&#x7684;&#x4E2A;&#x6570;&#x53D6;&#x4F59;&#xFF0C;&#x5982;&#x679C;&#x4F59;&#x6570;&#x5C0F;&#x4E8E; 0&#xFF0C;&#x5219;&#x7528;<code>&#x4F59;&#x6570;+&#x5206;&#x533A;&#x7684;&#x4E2A;&#x6570;</code>&#xFF08;&#x5426;&#x5219;&#x52A0;0&#xFF09;&#xFF0C;&#x6700;&#x540E;&#x8FD4;&#x56DE;&#x7684;&#x503C;&#x5C31;&#x662F;&#x8FD9;&#x4E2A;<code>key</code>&#x6240;&#x5C5E;&#x7684;&#x5206;&#x533A;<code>ID</code>&#x3002;</p>
<p><img src="http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/1549442353.png-atguiguText" alt=""></p>
<pre class="language-"><code class="lang-scala"><span class="token keyword">package</span> day01

<span class="token keyword">import</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>spark<span class="token punctuation">.</span>rdd<span class="token punctuation">.</span>RDD
<span class="token keyword">import</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>spark<span class="token punctuation">.</span><span class="token punctuation">{</span>HashPartitioner<span class="token punctuation">,</span> SparkConf<span class="token punctuation">,</span> SparkContext<span class="token punctuation">}</span>

<span class="token keyword">object</span> Test <span class="token punctuation">{</span>
    <span class="token keyword">def</span> main<span class="token punctuation">(</span>args<span class="token operator">:</span> Array<span class="token punctuation">[</span><span class="token builtin">String</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Unit</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
        <span class="token keyword">val</span> conf <span class="token operator">=</span> <span class="token keyword">new</span> SparkConf<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>setAppName<span class="token punctuation">(</span><span class="token string">&quot;Practice&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>setMaster<span class="token punctuation">(</span><span class="token string">&quot;local[2]&quot;</span><span class="token punctuation">)</span>
        <span class="token keyword">val</span> sc <span class="token operator">=</span> <span class="token keyword">new</span> SparkContext<span class="token punctuation">(</span>conf<span class="token punctuation">)</span>
        <span class="token keyword">val</span> rdd1 <span class="token operator">=</span> sc<span class="token punctuation">.</span>parallelize<span class="token punctuation">(</span>Array<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">&quot;a&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token string">&quot;b&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">&quot;c&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token string">&quot;d&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token string">&quot;e&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token number">60</span><span class="token punctuation">,</span> <span class="token string">&quot;f&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token comment">// &#x628A;&#x5206;&#x533A;&#x53F7;&#x53D6;&#x51FA;&#x6765;, &#x68C0;&#x67E5;&#x5143;&#x7D20;&#x7684;&#x5206;&#x533A;&#x60C5;&#x51B5;</span>
        <span class="token keyword">val</span> rdd2<span class="token operator">:</span> RDD<span class="token punctuation">[</span><span class="token punctuation">(</span><span class="token builtin">Int</span><span class="token punctuation">,</span> <span class="token builtin">String</span><span class="token punctuation">)</span><span class="token punctuation">]</span> <span class="token operator">=</span> rdd1<span class="token punctuation">.</span>mapPartitionsWithIndex<span class="token punctuation">(</span><span class="token punctuation">(</span>index<span class="token punctuation">,</span> it<span class="token punctuation">)</span> <span class="token keyword">=&gt;</span> it<span class="token punctuation">.</span>map<span class="token punctuation">(</span>x <span class="token keyword">=&gt;</span> <span class="token punctuation">(</span>index<span class="token punctuation">,</span> x<span class="token punctuation">.</span>_1 <span class="token operator">+</span> <span class="token string">&quot; : &quot;</span> <span class="token operator">+</span> x<span class="token punctuation">.</span>_2<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

        println<span class="token punctuation">(</span>rdd2<span class="token punctuation">.</span>collect<span class="token punctuation">.</span>mkString<span class="token punctuation">(</span><span class="token string">&quot;,&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

        <span class="token comment">// &#x628A; RDD1&#x4F7F;&#x7528; HashPartitioner&#x91CD;&#x65B0;&#x5206;&#x533A;</span>
        <span class="token keyword">val</span> rdd3 <span class="token operator">=</span> rdd1<span class="token punctuation">.</span>partitionBy<span class="token punctuation">(</span><span class="token keyword">new</span> HashPartitioner<span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token comment">// &#x68C0;&#x6D4B;RDD3&#x7684;&#x5206;&#x533A;&#x60C5;&#x51B5;</span>
        <span class="token keyword">val</span> rdd4<span class="token operator">:</span> RDD<span class="token punctuation">[</span><span class="token punctuation">(</span><span class="token builtin">Int</span><span class="token punctuation">,</span> <span class="token builtin">String</span><span class="token punctuation">)</span><span class="token punctuation">]</span> <span class="token operator">=</span> rdd3<span class="token punctuation">.</span>mapPartitionsWithIndex<span class="token punctuation">(</span><span class="token punctuation">(</span>index<span class="token punctuation">,</span> it<span class="token punctuation">)</span> <span class="token keyword">=&gt;</span> it<span class="token punctuation">.</span>map<span class="token punctuation">(</span>x <span class="token keyword">=&gt;</span> <span class="token punctuation">(</span>index<span class="token punctuation">,</span> x<span class="token punctuation">.</span>_1 <span class="token operator">+</span> <span class="token string">&quot; : &quot;</span> <span class="token operator">+</span> x<span class="token punctuation">.</span>_2<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        println<span class="token punctuation">(</span>rdd4<span class="token punctuation">.</span>collect<span class="token punctuation">.</span>mkString<span class="token punctuation">(</span><span class="token string">&quot;,&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>


    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p><img src="http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/1549444398.png-atguiguText" alt=""></p>
<hr>
<h2 id="rangepartitioner"><code>RangePartitioner</code></h2>
<p><code>HashPartitioner</code> &#x5206;&#x533A;&#x5F0A;&#x7AEF;&#xFF1A; &#x53EF;&#x80FD;&#x5BFC;&#x81F4;&#x6BCF;&#x4E2A;&#x5206;&#x533A;&#x4E2D;&#x6570;&#x636E;&#x91CF;&#x7684;&#x4E0D;&#x5747;&#x5300;&#xFF0C;&#x6781;&#x7AEF;&#x60C5;&#x51B5;&#x4E0B;&#x4F1A;&#x5BFC;&#x81F4;&#x67D0;&#x4E9B;&#x5206;&#x533A;&#x62E5;&#x6709; RDD &#x7684;&#x5168;&#x90E8;&#x6570;&#x636E;&#x3002;&#x6BD4;&#x5982;&#x6211;&#x4EEC;&#x524D;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x6781;&#x7AEF;, &#x4ED6;&#x4EEC;&#x90FD;&#x8FDB;&#x5165;&#x4E86; 0 &#x5206;&#x533A;.</p>
<p><code>RangePartitioner</code> &#x4F5C;&#x7528;&#xFF1A;&#x5C06;&#x4E00;&#x5B9A;&#x8303;&#x56F4;&#x5185;&#x7684;&#x6570;&#x6620;&#x5C04;&#x5230;&#x67D0;&#x4E00;&#x4E2A;&#x5206;&#x533A;&#x5185;&#xFF0C;&#x5C3D;&#x91CF;&#x4FDD;&#x8BC1;&#x6BCF;&#x4E2A;&#x5206;&#x533A;&#x4E2D;&#x6570;&#x636E;&#x91CF;&#x7684;&#x5747;&#x5300;&#xFF0C;&#x800C;&#x4E14;&#x5206;&#x533A;&#x4E0E;&#x5206;&#x533A;&#x4E4B;&#x95F4;&#x662F;&#x6709;&#x5E8F;&#x7684;&#xFF0C;&#x4E00;&#x4E2A;&#x5206;&#x533A;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x80AF;&#x5B9A;&#x90FD;&#x662F;&#x6BD4;&#x53E6;&#x4E00;&#x4E2A;&#x5206;&#x533A;&#x5185;&#x7684;&#x5143;&#x7D20;&#x5C0F;&#x6216;&#x8005;&#x5927;&#xFF0C;&#x4F46;&#x662F;&#x5206;&#x533A;&#x5185;&#x7684;&#x5143;&#x7D20;&#x662F;&#x4E0D;&#x80FD;&#x4FDD;&#x8BC1;&#x987A;&#x5E8F;&#x7684;&#x3002;&#x7B80;&#x5355;&#x7684;&#x8BF4;&#x5C31;&#x662F;&#x5C06;&#x4E00;&#x5B9A;&#x8303;&#x56F4;&#x5185;&#x7684;&#x6570;&#x6620;&#x5C04;&#x5230;&#x67D0;&#x4E00;&#x4E2A;&#x5206;&#x533A;&#x5185;&#x3002;&#x5B9E;&#x73B0;&#x8FC7;&#x7A0B;&#x4E3A;&#xFF1A;</p>
<p>&#x7B2C;&#x4E00;&#x6B65;&#xFF1A;&#x5148;&#x4ECE;&#x6574;&#x4E2A; RDD &#x4E2D;&#x62BD;&#x53D6;&#x51FA;&#x6837;&#x672C;&#x6570;&#x636E;&#xFF0C;&#x5C06;&#x6837;&#x672C;&#x6570;&#x636E;&#x6392;&#x5E8F;&#xFF0C;&#x8BA1;&#x7B97;&#x51FA;&#x6BCF;&#x4E2A;&#x5206;&#x533A;&#x7684;&#x6700;&#x5927; <code>key</code> &#x503C;&#xFF0C;&#x5F62;&#x6210;&#x4E00;&#x4E2A;<code>Array[KEY]</code>&#x7C7B;&#x578B;&#x7684;&#x6570;&#x7EC4;&#x53D8;&#x91CF; <code>rangeBounds</code>&#xFF1B;(&#x8FB9;&#x754C;&#x6570;&#x7EC4;). </p>
<p>&#x7B2C;&#x4E8C;&#x6B65;&#xFF1A;&#x5224;&#x65AD;<code>key</code>&#x5728;<code>rangeBounds</code>&#x4E2D;&#x6240;&#x5904;&#x7684;&#x8303;&#x56F4;&#xFF0C;&#x7ED9;&#x51FA;&#x8BE5;<code>key</code>&#x503C;&#x5728;&#x4E0B;&#x4E00;&#x4E2A;<code>RDD</code>&#x4E2D;&#x7684;&#x5206;&#x533A;<code>id</code>&#x4E0B;&#x6807;&#xFF1B;&#x8BE5;&#x5206;&#x533A;&#x5668;&#x8981;&#x6C42; RDD &#x4E2D;&#x7684; <code>KEY</code> &#x7C7B;&#x578B;&#x5FC5;&#x987B;&#x662F;&#x53EF;&#x4EE5;&#x6392;&#x5E8F;&#x7684;.</p>
<p>&#x6BD4;&#x5982;[1,100,200,300,400]&#xFF0C;&#x7136;&#x540E;&#x5BF9;&#x6BD4;&#x4F20;&#x8FDB;&#x6765;&#x7684;<code>key</code>&#xFF0C;&#x8FD4;&#x56DE;&#x5BF9;&#x5E94;&#x7684;&#x5206;&#x533A;<code>id</code>&#x3002;</p>
<hr>
<h2 id="&#x81EA;&#x5B9A;&#x4E49;&#x5206;&#x533A;&#x5668;">&#x81EA;&#x5B9A;&#x4E49;&#x5206;&#x533A;&#x5668;</h2>
<p>&#x8981;&#x5B9E;&#x73B0;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x5206;&#x533A;&#x5668;&#xFF0C;&#x4F60;&#x9700;&#x8981;&#x7EE7;&#x627F; <code>org.apache.spark.Partitioner</code>, &#x5E76;&#x4E14;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4E0B;&#x9762;&#x7684;&#x65B9;&#x6CD5;:</p>
<ol>
<li><p><code>numPartitions</code></p>
<p> &#x8BE5;&#x65B9;&#x6CD5;&#x9700;&#x8981;&#x8FD4;&#x56DE;&#x5206;&#x533A;&#x6570;, &#x5FC5;&#x987B;&#x8981;&#x5927;&#x4E8E;0.</p>
</li>
<li><p><code>getPartition(key)</code></p>
<p> &#x8FD4;&#x56DE;&#x6307;&#x5B9A;&#x952E;&#x7684;&#x5206;&#x533A;&#x7F16;&#x53F7;(0&#x5230;numPartitions-1)&#x3002;</p>
</li>
<li><p><code>equals</code></p>
<p> Java &#x5224;&#x65AD;&#x76F8;&#x7B49;&#x6027;&#x7684;&#x6807;&#x51C6;&#x65B9;&#x6CD5;&#x3002;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x5B9E;&#x73B0;&#x975E;&#x5E38;&#x91CD;&#x8981;&#xFF0C;Spark &#x9700;&#x8981;&#x7528;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x6765;&#x68C0;&#x67E5;&#x4F60;&#x7684;&#x5206;&#x533A;&#x5668;&#x5BF9;&#x8C61;&#x662F;&#x5426;&#x548C;&#x5176;&#x4ED6;&#x5206;&#x533A;&#x5668;&#x5B9E;&#x4F8B;&#x76F8;&#x540C;&#xFF0C;&#x8FD9;&#x6837; Spark &#x624D;&#x53EF;&#x4EE5;&#x5224;&#x65AD;&#x4E24;&#x4E2A; RDD &#x7684;&#x5206;&#x533A;&#x65B9;&#x5F0F;&#x662F;&#x5426;&#x76F8;&#x540C;</p>
</li>
<li><p><code>hashCode</code></p>
<p> &#x5982;&#x679C;&#x4F60;&#x8986;&#x5199;&#x4E86;<code>equals</code>, &#x5219;&#x4E5F;&#x5E94;&#x8BE5;&#x8986;&#x5199;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;.</p>
</li>
</ol>
<h3 id="mypartitioner"><code>MyPartitioner</code></h3>
<pre class="language-"><code class="lang-scala"><span class="token keyword">package</span> day04

<span class="token keyword">import</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>spark<span class="token punctuation">.</span>rdd<span class="token punctuation">.</span>RDD
<span class="token keyword">import</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>spark<span class="token punctuation">.</span><span class="token punctuation">{</span>Partitioner<span class="token punctuation">,</span> SparkConf<span class="token punctuation">,</span> SparkContext<span class="token punctuation">}</span>
<span class="token comment">/*
&#x4F7F;&#x7528;&#x81EA;&#x5B9A;&#x4E49;&#x7684; Partitioner &#x662F;&#x5F88;&#x5BB9;&#x6613;&#x7684; :&#x53EA;&#x8981;&#x628A;&#x5B83;&#x4F20;&#x7ED9; partitionBy() &#x65B9;&#x6CD5;&#x5373;&#x53EF;&#x3002;

Spark &#x4E2D;&#x6709;&#x8BB8;&#x591A;&#x4F9D;&#x8D56;&#x4E8E;&#x6570;&#x636E;&#x6DF7;&#x6D17;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x6BD4;&#x5982; join() &#x548C; groupByKey()&#xFF0C;
&#x5B83;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x63A5;&#x6536;&#x4E00;&#x4E2A;&#x53EF;&#x9009;&#x7684; Partitioner &#x5BF9;&#x8C61;&#x6765;&#x63A7;&#x5236;&#x8F93;&#x51FA;&#x6570;&#x636E;&#x7684;&#x5206;&#x533A;&#x65B9;&#x5F0F;&#x3002;
*/</span>
<span class="token keyword">object</span> MyPartitionerDemo <span class="token punctuation">{</span>
    <span class="token keyword">def</span> main<span class="token punctuation">(</span>args<span class="token operator">:</span> Array<span class="token punctuation">[</span><span class="token builtin">String</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Unit</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
        <span class="token keyword">val</span> conf <span class="token operator">=</span> <span class="token keyword">new</span> SparkConf<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>setAppName<span class="token punctuation">(</span><span class="token string">&quot;Practice&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>setMaster<span class="token punctuation">(</span><span class="token string">&quot;local[*]&quot;</span><span class="token punctuation">)</span>
        <span class="token keyword">val</span> sc <span class="token operator">=</span> <span class="token keyword">new</span> SparkContext<span class="token punctuation">(</span>conf<span class="token punctuation">)</span>

        <span class="token keyword">val</span> rdd1 <span class="token operator">=</span> sc<span class="token punctuation">.</span>parallelize<span class="token punctuation">(</span>
            Array<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">&quot;a&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token string">&quot;b&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">&quot;c&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span> <span class="token string">&quot;d&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">,</span> <span class="token string">&quot;e&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token number">60</span><span class="token punctuation">,</span> <span class="token string">&quot;f&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token number">3</span><span class="token punctuation">)</span>
        <span class="token keyword">val</span> rdd2<span class="token operator">:</span> RDD<span class="token punctuation">[</span><span class="token punctuation">(</span><span class="token builtin">Int</span><span class="token punctuation">,</span> <span class="token builtin">String</span><span class="token punctuation">)</span><span class="token punctuation">]</span> <span class="token operator">=</span> rdd1<span class="token punctuation">.</span>partitionBy<span class="token punctuation">(</span><span class="token keyword">new</span> MyPartitioner<span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token keyword">val</span> rdd3<span class="token operator">:</span> RDD<span class="token punctuation">[</span><span class="token punctuation">(</span><span class="token builtin">Int</span><span class="token punctuation">,</span> <span class="token builtin">String</span><span class="token punctuation">)</span><span class="token punctuation">]</span> <span class="token operator">=</span> rdd2<span class="token punctuation">.</span>mapPartitionsWithIndex<span class="token punctuation">(</span><span class="token punctuation">(</span>index<span class="token punctuation">,</span> items<span class="token punctuation">)</span> <span class="token keyword">=&gt;</span> items<span class="token punctuation">.</span>map<span class="token punctuation">(</span>x <span class="token keyword">=&gt;</span> <span class="token punctuation">(</span>index<span class="token punctuation">,</span> x<span class="token punctuation">.</span>_1 <span class="token operator">+</span> <span class="token string">&quot; : &quot;</span> <span class="token operator">+</span> x<span class="token punctuation">.</span>_2<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        println<span class="token punctuation">(</span>rdd3<span class="token punctuation">.</span>collect<span class="token punctuation">.</span>mkString<span class="token punctuation">(</span><span class="token string">&quot; &quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> MyPartitioner<span class="token punctuation">(</span>numPars<span class="token operator">:</span> <span class="token builtin">Int</span><span class="token punctuation">)</span> <span class="token keyword">extends</span> Partitioner <span class="token punctuation">{</span>
    <span class="token keyword">override</span> <span class="token keyword">def</span> numPartitions<span class="token operator">:</span> <span class="token builtin">Int</span> <span class="token operator">=</span> numPars


    <span class="token keyword">override</span> <span class="token keyword">def</span> getPartition<span class="token punctuation">(</span>key<span class="token operator">:</span> <span class="token builtin">Any</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Int</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
        <span class="token number">1</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; &#x5C1A;&#x7845;&#x8C37;&#x5927;&#x6570;&#x636E; 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification"><br>&#x8BE5;&#x6587;&#x4EF6;&#x6700;&#x540E;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2019-04-22 22:12:59
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="di-5-zhang-rdd-bian-cheng/510-she-zhi-jian-cha-dian.html" class="navigation navigation-prev " aria-label="Previous page: 5.10 设置检查点">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="di-7-zhang.html" class="navigation navigation-next " aria-label="Next page: 第 7 章 文件中数据的读取和保存">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"第 6 章 Key-Value 类型 RDD 的数据分区器","level":"2.3","depth":1,"next":{"title":"第 7 章 文件中数据的读取和保存","level":"2.4","depth":1,"path":"di-2-bu-fen-spark-core/di-7-zhang.md","ref":"di-2-bu-fen-spark-core/di-7-zhang.md","articles":[{"title":"7.1 读写 Text 文件","level":"2.4.1","depth":2,"path":"di-2-bu-fen-spark-core/di-7-zhang/71-du-xie-text-wen-jian.md","ref":"di-2-bu-fen-spark-core/di-7-zhang/71-du-xie-text-wen-jian.md","articles":[]},{"title":"7.2 读写 Json 文件","level":"2.4.2","depth":2,"path":"di-2-bu-fen-spark-core/di-7-zhang/72-du-xie-json-wen-jian.md","ref":"di-2-bu-fen-spark-core/di-7-zhang/72-du-xie-json-wen-jian.md","articles":[]},{"title":"7.3 读写 Sequence 文件","level":"2.4.3","depth":2,"path":"di-2-bu-fen-spark-core/di-7-zhang/73-du-xie-sequence-wen-jian.md","ref":"di-2-bu-fen-spark-core/di-7-zhang/73-du-xie-sequence-wen-jian.md","articles":[]},{"title":"7.4 读写 Object 文件","level":"2.4.4","depth":2,"path":"di-2-bu-fen-spark-core/di-7-zhang/74-du-xie-object-wen-jian.md","ref":"di-2-bu-fen-spark-core/di-7-zhang/74-du-xie-object-wen-jian.md","articles":[]},{"title":"7.5 从 HDFS 读写文件","level":"2.4.5","depth":2,"path":"di-2-bu-fen-spark-core/di-7-zhang/75-cong-hdfs-du-xie-wen-jian.md","ref":"di-2-bu-fen-spark-core/di-7-zhang/75-cong-hdfs-du-xie-wen-jian.md","articles":[]},{"title":"7.6 从 Mysql 数据读写文件","level":"2.4.6","depth":2,"path":"di-2-bu-fen-spark-core/di-7-zhang/76-cong-mysql-shu-ju-du-xie-wen-jian.md","ref":"di-2-bu-fen-spark-core/di-7-zhang/76-cong-mysql-shu-ju-du-xie-wen-jian.md","articles":[]},{"title":"7.7 从 Hbase 读写文件","level":"2.4.7","depth":2,"path":"di-2-bu-fen-spark-core/di-7-zhang/77-cong-hbase-du-xie-wen-jian.md","ref":"di-2-bu-fen-spark-core/di-7-zhang/77-cong-hbase-du-xie-wen-jian.md","articles":[]}]},"previous":{"title":"5.10 设置检查点","level":"2.2.10","depth":2,"path":"di-2-bu-fen-spark-core/di-5-zhang-rdd-bian-cheng/510-she-zhi-jian-cha-dian.md","ref":"di-2-bu-fen-spark-core/di-5-zhang-rdd-bian-cheng/510-she-zhi-jian-cha-dian.md","articles":[]},"dir":"ltr"},"config":{"plugins":["splitter","expandable-chapters-small","page-toc-button","-highlight","prism","prism-themes","tbfed-pagefooter","sitemap","change_girls","livereload"],"styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy 尚硅谷大数据 2019","modify_label":"<br>该文件最后修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prismjs/themes/prism-solarizedlight.css"]},"disqus":{"shortName":"zhenchao125"},"livereload":{},"splitter":{},"change_girls":{"time":30,"urls":["http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/62171757.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/83394736.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/15906185.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/15906185.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/3394270.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/65028582.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/20359261.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/37472401.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/3355397.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/11075549.jpg-atguiguImg"]},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"sitemap":{"hostname":"http://bigdataatguigu.applinzi.com/"},"page-toc-button":{"maxTocDepth":3,"minTocSize":2},"prism-themes":{},"expandable-chapters-small":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":" 李振超","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"大数据 bigdata_spark_atguigu 课堂笔记","language":"zh-hans","links":{"sidebar":{"联系我们":"http://www.atguigu.com/"}},"gitbook":"*","description":"课堂笔记,学生提前预习"},"file":{"path":"di-2-bu-fen-spark-core/di-6-zhang-key-value-lei-xing-rdd-de-shu-ju-fen-qu.md","mtime":"2019-04-22T14:12:59.534Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-07-12T00:29:24.298Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-change_girls/girls.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

